/**
 * 
 */
package com.zufangbao.earth.web.controller.assets;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.web.interceptor.MenuSetting;
import com.demo2do.core.web.resolver.Page;
import com.zufangbao.sun.entity.house.House;
import com.zufangbao.sun.service.HouseService;

/**
 * @author Downpour
 */
@Controller
@RequestMapping("/houses")
@MenuSetting("menu-data")
public class HouseController {

	@Autowired
	private HouseService houseService;
	/**
	 * List app houses
	 * 
	 * @return
	 */
	@RequestMapping("")
	@MenuSetting("submenu-assets-house")
	public ModelAndView list(Page page) {
		
		List<House> houseList = houseService.list(House.class, page);
		
		ModelAndView modelAndView = new ModelAndView("house/house-list");
		modelAndView.addObject("houseList", houseList);
		modelAndView.addObject("page", page);
		
		return modelAndView;
	}
	
	
	/**
	 *show app house detail
	 * 
	 * @return
	 */
	@RequestMapping("/{houseId}/detail")
	public ModelAndView detail(@PathVariable Long houseId) {
		
		House house = houseService.load(House.class, houseId);
		ModelAndView modelAndView = new ModelAndView("house/house-detail");
		
		modelAndView.addObject("house", house);
		
		return modelAndView;
	}
	
}
